package lcr;

import java.util.Arrays;

public class Test0020 {
}

class Solution0020_1 {
    public int countSubstrings(String s) {
        int length = s.length(),result=0;
        boolean[] dp = new boolean[length+1];
        Arrays.fill(dp,true);
        char[] charArray = s.toCharArray();

        for (int i = 0; i < length; i++) {
            char c = charArray[i];
            for (int j = 0; j <= i; j++) {
                if (c==charArray[j]&&dp[j+1]){
                    result++;
                    dp[j]=true;
                }else {
                    dp[j]=false;
                }
            }
        }

        return result;
    }
}
